package framework.agent;


import framework.task.Task;
import jade.core.AID;
import jade.core.Agent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * @Name: CustomAgent
 * @Description:
 * @Author: colfish
 * @Date: 2021/5/13 15:30
 * 好好学习，天天向上！
 */
public class CustomAgent extends Agent {
    private static final long serialVersionUID = -6300426945738475440L;
    private Logger logger = LogManager.getLogger(Task.class);

    private int agentId;

    private String action;

    public CustomAgent(){

    }

    @Override
    protected void setup() {
        super.setup();
    }

    /**
     * 将自身Agent设置为任务对象的myAgent，但没有给自身Agent添
     * 加task中的Behaviour，添加Behaviours的动作放在Task的
     * doTask()方法中
     * @param task 添加的任务对象
     */
    public void takeTask(Task task){
        if(task == null){
            logger.error("Task can't be null!");
        }
        assert task != null;
        task.setAgent(this);
        logger.info(this.getLocalName() + " take " + task.getTaskName());
    }

    /**
     * 释放任务对象，删除任务中的行为，并设置任务中的myAgent为null
     * @param task
     */
    public void releaseTask(Task task){
        if(task == null){
            logger.error("Task can't be null!");
        }
        assert task != null;
        this.removeBehaviour(task.getBehaviour());
        task.setAgent(null);
    }

    public int getAgentId() {
        return agentId;
    }

    public void setAgentId(int agentId) {
        this.agentId = agentId;
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }
}
